package nio.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
//拷贝
public class channelDemo_4 {
    public static void main(String[] args) throws IOException {
        //创建输入流
        FileInputStream fileInputStream = new FileInputStream("1.jpg");
        FileChannel channel1 = fileInputStream.getChannel();
        //创建输出流
        FileOutputStream fileOutputStream = new FileOutputStream("2.jpg");
        FileChannel channel2 = fileOutputStream.getChannel();
        //拷贝
        channel2.transferFrom(channel1,0,channel1.size());
        //关闭通道
        channel1.close();
        channel2.close();
        //关闭流
        fileInputStream.close();
        fileOutputStream.close();
    }

}
